/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.test_finder;

import picounit.features.Feature;
import picounit.features.base.FeatureRegistry;
import picounit.features.test_instantiator.TestInstantiationException;
import picounit.features.test_instantiator.TestInstantiator;

public class SimpleFinderFeature implements Feature {
	public void addFeatures(FeatureRegistry featureRegistry) {
		featureRegistry.add(TestInstantiator.class, new SimpleTestInstantiator());
	}

	static class SimpleTestInstantiator implements TestInstantiator {
		public <T> T instantiate(Class<T> testClass) {
			try {
				return testClass.newInstance();
			}
			catch (IllegalArgumentException illegalArgumentException) {
				throw new TestInstantiationException(illegalArgumentException);
			}
			catch (IllegalAccessException illegalAccessException) {
				throw new TestInstantiationException(illegalAccessException);
			}
			catch (InstantiationException instantiationException) {
				throw new TestInstantiationException(instantiationException);
			}
		}
	}
}
